package com.github.natholdallas.database

import com.github.natholdallas.common.CURTIME
import jakarta.persistence.*
import org.springframework.data.annotation.CreatedDate
import org.springframework.data.annotation.LastModifiedDate
import org.springframework.data.jpa.domain.support.AuditingEntityListener

@Suppress("UNUSED")
interface LongIdTableModel {
    var id: Long?
}


@Suppress("UNUSED")
interface RecordModel {
    var createTime: Long
    var updateTime: Long
}


@Suppress("UNUSED")
interface LongIdRecordModel : LongIdTableModel, RecordModel


@[MappedSuperclass EntityListeners(AuditingEntityListener::class) Suppress("UNUSED")]
open class IRecordModel(
    @CreatedDate
    override var createTime: Long = CURTIME,
    @LastModifiedDate
    override var updateTime: Long = CURTIME
) : RecordModel


@[MappedSuperclass Suppress("UNUSED")]
open class ILongIdTableModel(
    @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
    override var id: Long? = null
) : LongIdTableModel


@[MappedSuperclass EntityListeners(AuditingEntityListener::class) Suppress("UNUSED")]
open class ILongIdRecordModel(
    @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
    override var id: Long? = null,
    @CreatedDate
    override var createTime: Long = CURTIME,
    @LastModifiedDate
    override var updateTime: Long = CURTIME
) : LongIdRecordModel
